package com.xiaomaoguai.security.web.controller;

import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @fileName: UserController.java
 * @author: WeiHui-Z
 * @date: 2017/11/22 20:52
 * @version: v1.0.0
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @GetMapping("/me")
    public Object me() {
        return SecurityContextHolder.getContext().getAuthentication();
    }

    @GetMapping("/me2")
    public Object getCurrentUser(@AuthenticationPrincipal UserDetails user) {
        return user;
    }

    @GetMapping
    public Object getUserList() {
        Map<String, String> userMap = new HashMap<>(10);
        userMap.put("name", "Jim ketty");
        userMap.put("age", "25");
        return userMap;
    }
}
